﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using KMT_Pro.ViewModels.ClientViewModels;
using KMT_Pro.Utils;
using System.Windows.Threading;


namespace KMT_Pro.Views.ClientViews
{
    public partial class ClientEditUserView : ChildWindow
    {
        ClientEditUserViewModel viewModel = new ClientEditUserViewModel();
        public int countdown = 10;
        public string _CompanyName;
        DispatcherTimer myDispatcherTimer = new DispatcherTimer();

        public ClientEditUserView(string CompanyID, string CompanyName, string Name, string Tel, string Phone, string Fax, string Email, string Position, string etc, string idx, string IU)
        {
            InitializeComponent();
            this.DataContext = viewModel;

            var vm = this.DataContext as ClientEditUserViewModel;
            if (vm == null) return;
            vm.companyID = CompanyID;
            vm.CompanyName = CompanyName;
            vm.ClientName = Name;
            vm.Phone = Phone;
            vm.Fax = Fax;
            vm.Email = Email;
            vm.Position = Position;
            vm.Tel = Tel;
            vm.Etc = etc;
            vm.Idx = idx;
            vm.IU_info = IU;
            _CompanyName = CompanyID;

        }

        private void ChildWindow_Loaded(object sender, RoutedEventArgs e)
        {
            //콤보박스 로딩용 타이머
            myDispatcherTimer.Interval = new TimeSpan(0, 0, 0, 0, 100); // 100 Milliseconds 
            myDispatcherTimer.Tick += new EventHandler(Each_Tick);
            myDispatcherTimer.Start();
        }

        public void Each_Tick(object o, EventArgs sender)
        {
            try
            {
                CompanyCombo.SelectedValue = _CompanyName;
                myDispatcherTimer.Stop();
            }
            catch (Exception)
            { }
        }
 
        private void OKButton_Click(object sender, RoutedEventArgs e)
        {
            var vm = this.DataContext as ClientEditUserViewModel;
            if (vm == null) return;
            vm.editClick.Execute(null);
        }

        private void CancelButton_Click(object sender, RoutedEventArgs e)
        {
            this.DialogResult = true;
        }
    }
}

